package com.etoak.common.jwt;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.apache.commons.lang3.time.DateUtils;

import java.security.Key;
import java.util.Date;
import java.util.Map;

public class MyJwtUtil {
    public static final String STRING_KEY = "11111111111111111111111111111111";
    public static final Key KEY = Keys.hmacShaKeyFor(STRING_KEY.getBytes());
    public static String creat(Map<String, Object> claims) {
        Date now = new Date();
        return Jwts.builder()
                .signWith(KEY)
                .setClaims(claims)
                .setIssuedAt(now)
                .setExpiration(DateUtils.addHours(now,12))
                .compact();
    }
    public static Map<String,Object> parse(String token) {
        return Jwts.parserBuilder()
                .setSigningKey(KEY)
                .build()
                .parseClaimsJws(token)
                .getBody();
    }
}
